package com.hamster.crmpre.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hamster.crmpre.pojo.BigCompanyRecord;
import com.hamster.crmpre.pojo.dto.BigCompanyRecordDTO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * @author Tarry
 * @create 2020/1/6 22:48
 */
@Repository
@Mapper
public interface BigCompanyRecordMapper extends BaseMapper<BigCompanyRecord> {
    //查询 分公司上月记录
    @Select("select company_id from big_company_record where create_time >= #{startDate} and create_time < #{endDate}")
    @Results({
            @Result(property = "companyId",column = "company_id"),
            @Result(property = "records",column = "company_id",many = @Many(select = "com.hamster.crmpre.mapper.BigCompanyRecordMapper.queryRecord"))

    })
    List<BigCompanyRecordDTO> queryListByDate(@Param("startDate") Date startDate,@Param("endDate") Date endDate);

    @Select("select * from big_company_record where company_id = #{companyId}")
    @Results({
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "companyId",column = "company_id"),
            @Result(property = "customerId",column = "customer_id"),
            @Result(property = "customerName",column = "customer_name"),
            @Result(property = "projectId",column = "project_id"),
            @Result(property = "refund",column = "refund"),
            @Result(property = "createTime",column = "create_time")
    })
    List<BigCompanyRecord> queryRecord(@Param("companyId") String companyId);


}
